import {env} from "../utils/env"
  console.log(env.baseURL,'evn');
export const request = (options) => {
  let isLoading = false
  if (isLoading == false) {
    isLoading = true
    return new Promise((resolve, reject) => {
      wx.request({
        url: env.baseURL + options.url,
        method: options.methods || "GET",
        data: options.data || {},
        header: {
          "content-type": "application/json",
          "X-Access-Token": wx.getStorageSync("token") || "",
        },
        success: (res) => {
          if (res.data.code == 200) {
             isLoading = false
            resolve(res.data);
          } else if (res.data.code == 500) {
            wx.showModal({
              title: res.data.message || "服务端错误",
              icon: "none",
              duration:3000,
              showCancel:false
            });
          } else if (res.data.code == 404) {
            wx.showToast({
              title: "接口地址错误",
              icon: "error",
            });
          }else if(res.data.code == 401){
            wx.showToast({
              title: res.data.message,
              icon: "none",
            });
            setTimeout(() => {
              wx.reLaunch({
                url: '/pages/index/index'
              })
            }, 1500);
          }
        },
        fail: (err) => {
          console.log(err);
          try {
          } catch (error) {
            reject(err);
          }
        },
      });
    });
  }
  
};
